package de.bazinga.rotw.objects;

import com.jme.bounding.BoundingBox;
import com.jme.math.Ring;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Controller;
import com.jme.scene.Node;
import com.jmex.effects.particles.ParticleFactory;
import com.jmex.effects.particles.ParticleSystem;

import de.bazinga.rotw.person.Person;

public class BeamStation extends Node implements GameObject {
	private static final long serialVersionUID = 1L;
	
	private Vector3f aim = null;
	
	public BeamStation(Vector3f location, Vector3f aim) {
		this.aim = aim;
		
		
		// Effect
		ParticleSystem particleGeom = ParticleFactory.buildParticles("Beam", 600);
		particleGeom.setGeometry(new Ring(new Vector3f(0,0,0),
				new Vector3f(0,1f,0),
				0.5f,
				0.5f));
		particleGeom.setEmissionDirection(new Vector3f(0,1,0.0f));
		
		
		float pi = 3.14159265f;
        particleGeom.setMinimumAngle(0);
        particleGeom.setMaximumAngle((pi)/8.0f);
        particleGeom.setInitialVelocity(0.001f);
        particleGeom.setMinimumLifeTime(100.0f);
        particleGeom.setMaximumLifeTime(800.0f);
        particleGeom.setStartSize(0.006f);
        particleGeom.setEndSize(0.01f);
        particleGeom.setStartColor(ColorRGBA.red);
        particleGeom.setEndColor(ColorRGBA.yellow);
        particleGeom.getParticleController().setControlFlow(false);
        particleGeom.getParticleController().setRepeatType(
                Controller.RT_CYCLE);
        
        
        
        Node particleNode = new Node("Hit");
		particleNode.setLocalTranslation(location);
        particleNode.attachChild(particleGeom);

        
        particleNode.setModelBound(new BoundingBox());
        particleNode.updateModelBound();
        
        this.attachChild(particleNode);
	}

	public void onCollision(Person person, boolean sendMessage) {
		person.setLocalTranslation(aim.clone());
	}
	
	public void hide() {
		
	}
	
	public boolean respawn() {
		return true;
	}
}
